package gtv.sic.control;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import gtv.sic.R;
import gtv.sic.control.CadastroUsuarioActivity;
import gtv.sic.control.MenuPrincipalActivity;
import gtv.sic.dao.UsuarioDAO;

public class SiCActivity extends Activity {
	
	private TextView mensagem;
	private EditText login;
	private EditText senha;
	private Button entrar;
	private Button criarConta;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        login = (EditText) findViewById(R.id.login);
        senha = (EditText) findViewById(R.id.senha);
        entrar = (Button) findViewById(R.id.buttonEntrar);
        criarConta = (Button) findViewById(R.id.buttonCriarConta);
        mensagem = (TextView) findViewById(R.id.mensagem);
                   
        entrar.setOnClickListener(new View.OnClickListener() {
        	
			public void onClick(View v) {
        		
				UsuarioDAO dao = UsuarioDAO.getInstance();		
				
				if (dao.logon(login.getText().toString(), senha.getText().toString())) {
					Intent intent = new Intent(SiCActivity.this,MenuPrincipalActivity.class);
					startActivity(intent);
				} else {
					login.setText("");
					senha.setText("");
					mensagem.setText("Usuario ou senha invalida.");
				}
				
				
			}
		});
        
        criarConta.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				Intent intent = new Intent(SiCActivity.this, CadastroUsuarioActivity.class);
				
				startActivity(intent);
			}
		});
        
        
    }
}